
from config import *
import logging
       
def log_init():
       
    logger = logging.getLogger('dmzwatcher')
    try: 
        loglevel = getattr(logging, LOG_LEVEL.upper(), None)
        if not isinstance(loglevel, int):
            raise ValueError('Invalid log level: %s' % LOG_LEVEL)
    except:
        raise ValueError('Invalid log level: %s' % LOG_LEVEL)
    
    logger.setLevel(loglevel)    
    
    
    
    if LOGGING_ENABLE == False:
        logger.addHandler(logging.NullHandler)
        return
    
    if SYSLOG_ENABLE == True:
        sh = logging.SysLogHandler(address = (SYSLOG_ADDRESS, SYSLOG_PORT), facility = SYSLOG_FACILITY)
        
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        sh.setFormatter(formatter)
        
        logger.addHandler(sh)
    
    if LOGFILE_ENABLE == True:
        fh = logging.FileHandler(LOG_FILENAME)
        
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        fh.setFormatter(formatter)
        
        logger.addHandler(fh)


def log1():
    a = logging.getLogger('dmzwatcher.model')
    a.info('hello')
    